<?php
namespace app\admin\controller;
use app\admin\model\Grade;
use app\admin\model\Project;
use think\Db;
class Index extends Base
{
    /**
     * 后台首页
     * @return \think\response\View
     */
    public function index()
    {
        $li = Db::name('project')->where('status',2)->where('enable',2)->find();
        $this->assign('li',$li);
        return view();
    }

    /**
     * 比赛项目
     */
    public function matchList()
    {
        $pro = new Project();
        $list = $pro->where('status','<>',3)->where('enable',2)->order('create_time','asc')->select();
        $this->assign('list',$list);
        $li = Db::name('project')->where('status',2)->where('enable',2)->find();
        $this->assign('li',$li);
        return view();
    }

    /**
     * 比赛记录
     */
    public function history()
    {
        $li = Db::name('project')->where('status',2)->where('enable',2)->find();
        $this->assign('li',$li);
        $grade = new Grade();
        $list = $grade->alias('g')
                      ->join('project p','g.pid=p.id')
                      ->where('g.enable',2)
                      ->order('p.update_time','desc')
                      ->select();
        $this->assign('list',$list);
        return view();
    }

    /**
     * 账号设置
     */
    public function setAccount()
    {
        $list = Db::name('account')->where('enable',2)->select();
        $this->assign('list',$list);
        $li = Db::name('project')->where('status',2)->where('enable',2)->find();
        $this->assign('li',$li);
        return view();
    }

    /**
     * 正在进行
     */
    public function running()
    {
        $li = Db::name('project')->where('status',2)->where('enable',2)->find();
        $this->assign('li',$li);
        $pro = new Program();
        $list = $pro->avg($li['id']);
        $this->assign('list',$list);
		$this->assign('puship',config('puship'));
        return view();
    }

    /**
     * 参赛选手
     */
    public function player()
    {
        $li = Db::name('project')->where('status',2)->where('enable',2)->find();
        $this->assign('li',$li);
        $list = Db::name('sign')->where('enable',2)->select();
        $this->assign('list',$list);
        return view();
    }

    /**
     * 公共部分
     */
//    public function pub()
//    {
//        $list = Db::name('project')->where('status',2)->where('enable',2)->find();
//        $this->assign('list',$list);
//        return view('public/header');
//    }
}
